<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>高端新闻曝光服务方案生成器</title>
    <link href="https://cdn.bootcdn.net/ajax/libs/bootstrap/5.3.2/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdn.bootcdn.net/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <style>
        :root {
            --primary-blue: #175278;
            --primary-gold: #DCA046;
            --light-gray: #f8f9fa;
            --dark-gray: #1e1e1e;
        }
        
        body {
            background-color: var(--light-gray);
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
        }
        
        .header {
            background: linear-gradient(135deg, var(--primary-blue), var(--primary-gold));
            color: white;
            padding: 2rem 0;
            margin-bottom: 2rem;
        }
        
        .preview-card {
            background: white;
            border-radius: 10px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
            overflow: hidden;
        }
        
        .preview-header {
            background: var(--dark-gray);
            color: white;
            padding: 1.5rem;
            text-align: center;
        }
        
        .preview-body {
            padding: 2rem;
            min-height: 300px;
            display: flex;
            align-items: center;
            justify-content: center;
            background: linear-gradient(135deg, var(--primary-blue), var(--primary-gold));
            color: white;
        }
        
        .btn-generate {
            background: var(--primary-gold);
            border-color: var(--primary-gold);
            color: white;
            font-weight: bold;
            padding: 0.75rem 2rem;
        }
        
        .btn-generate:hover {
            background: #b8862b;
            border-color: #b8862b;
            color: white;
        }
        
        .form-section {
            background: white;
            border-radius: 10px;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
            padding: 2rem;
            margin-bottom: 2rem;
        }
        
        .news-item {
            margin-bottom: 0.5rem;
        }
    </style>
</head>
<body>
    <div class="header">
        <div class="container">
            <h1 class="text-center mb-0">
                <i class="fas fa-file-powerpoint me-2"></i>
                高端新闻曝光服务方案生成器
            </h1>
            <p class="text-center mb-0 mt-2">一键生成专业级PPT演示文稿</p>
        </div>
    </div>

    <div class="container">
        <div class="row">
            <div class="col-lg-6">
                <div class="form-section">
                    <h3 class="mb-3">
                        <i class="fas fa-edit me-2"></i>
                        方案配置
                    </h3>
                    
                    <form id="pptForm">
                        <div class="mb-3">
                            <label for="title" class="form-label">主标题</label>
                            <input type="text" class="form-control" id="title" placeholder="高端新闻曝光服务方案" required>
                        </div>
                        
                        <div class="mb-3">
                            <label for="subtitle" class="form-label">副标题</label>
                            <input type="text" class="form-control" id="subtitle" placeholder="专业媒体传播解决方案">
                        </div>
                        
                        <div class="mb-3">
                            <label for="company" class="form-label">公司名称</label>
                            <input type="text" class="form-control" id="company" placeholder="请输入您的公司名称">
                        </div>
                        
                        <div class="mb-3">
                            <label for="logo" class="form-label">公司Logo</label>
                            <input type="file" class="form-control" id="logo" accept="image/*">
                        </div>
                        
                        <div class="mb-3">
                            <label class="form-label">新闻要点</label>
                            <div id="newsPoints">
                                <div class="input-group mb-2 news-item">
                                    <input type="text" class="form-control" placeholder="新闻要点1" required>
                                    <button class="btn btn-outline-danger" type="button" onclick="removeNewsItem(this)">
                                        <i class="fas fa-trash"></i>
                                    </button>
                                </div>
                            </div>
                            <button type="button" class="btn btn-outline-primary btn-sm" onclick="addNewsItem()">
                                <i class="fas fa-plus me-1"></i>添加要点
                            </button>
                        </div>
                        
                        <button type="submit" class="btn btn-generate w-100">
                            <i class="fas fa-magic me-2"></i>
                            生成PPT方案
                        </button>
                    </form>
                </div>
            </div>
            
            <div class="col-lg-6">
                <div class="preview-card">
                    <div class="preview-header">
                        <h5 class="mb-0">
                            <i class="fas fa-eye me-2"></i>
                            实时预览
                        </h5>
                    </div>
                    <div class="preview-body">
                        <div class="text-center">
                            <h2 id="previewTitle">高端新闻曝光服务方案</h2>
                            <p id="previewSubtitle" class="lead">专业媒体传播解决方案</p>
                            <div id="previewCompany" class="mt-3"></div>
                        </div>
                    </div>
                </div>
                
                <div class="mt-3" id="downloadSection" style="display: none;">
                    <div class="alert alert-success">
                        <i class="fas fa-check-circle me-2"></i>
                        PPT文件已生成完成！
                        <a href="#" id="downloadLink" class="btn btn-success btn-sm ms-2">
                            <i class="fas fa-download me-1"></i>
                            立即下载
                        </a>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script src="https://cdn.bootcdn.net/ajax/libs/bootstrap/5.3.2/js/bootstrap.bundle.min.js"></script>
    <script>
        // 实时预览更新
        document.getElementById('title').addEventListener('input', function(e) {
            document.getElementById('previewTitle').textContent = e.target.value || '高端新闻曝光服务方案';
        });
        
        document.getElementById('subtitle').addEventListener('input', function(e) {
            document.getElementById('previewSubtitle').textContent = e.target.value || '专业媒体传播解决方案';
        });
        
        document.getElementById('company').addEventListener('input', function(e) {
            const companyDiv = document.getElementById('previewCompany');
            if (e.target.value) {
                companyDiv.innerHTML = `<small class="text-light">${e.target.value}</small>`;
            } else {
                companyDiv.innerHTML = '';
            }
        });
        
        // 添加新闻要点
        function addNewsItem() {
            const container = document.getElementById('newsPoints');
            const newItem = document.createElement('div');
            newItem.className = 'input-group mb-2 news-item';
            newItem.innerHTML = `
                <input type="text" class="form-control" placeholder="新闻要点${container.children.length + 1}" required>
                <button class="btn btn-outline-danger" type="button" onclick="removeNewsItem(this)">
                    <i class="fas fa-trash"></i>
                </button>
            `;
            container.appendChild(newItem);
        }
        
        // 删除新闻要点
        function removeNewsItem(button) {
            const item = button.closest('.news-item');
            item.remove();
        }
        
        // 表单提交
        document.getElementById('pptForm').addEventListener('submit', async function(e) {
            e.preventDefault();
            
            const formData = new FormData();
            formData.append('title', document.getElementById('title').value);
            formData.append('subtitle', document.getElementById('subtitle').value);
            formData.append('company', document.getElementById('company').value);
            
            // 收集新闻要点
            const newsPoints = [];
            document.querySelectorAll('#newsPoints input').forEach(input => {
                if (input.value.trim()) {
                    newsPoints.push(input.value.trim());
                }
            });
            formData.append('news_points', JSON.stringify(newsPoints));
            
            // 添加Logo
            const logoFile = document.getElementById('logo').files[0];
            if (logoFile) {
                formData.append('logo', logoFile);
            }
            
            // 显示加载状态
            const submitBtn = e.target.querySelector('button[type="submit"]');
            const originalText = submitBtn.innerHTML;
            submitBtn.innerHTML = '<i class="fas fa-spinner fa-spin me-2"></i>生成中...';
            submitBtn.disabled = true;
            
            try {
                const response = await fetch('http://localhost:8000/generate', {
                    method: 'POST',
                    body: formData
                });
                
                if (response.ok) {
                    const blob = await response.blob();
                    const url = window.URL.createObjectURL(blob);
                    const a = document.getElementById('downloadLink');
                    a.href = url;
                    a.download = `高端新闻曝光服务方案_${new Date().getTime()}.pptx`;
                    document.getElementById('downloadSection').style.display = 'block';
                    a.click();
                } else {
                    alert('生成失败，请重试');
                }
            } catch (error) {
                console.error('Error:', error);
                alert('网络错误，请检查后端服务是否运行');
            } finally {
                submitBtn.innerHTML = originalText;
                submitBtn.disabled = false;
            }
        });
    </script>
</body>
</html>